import { localCache } from '@/utils/cache'
import { BASE_URL, TIME_OUT } from './config'
import HYRequest from './request'

const hyRequest = new HYRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  // 设置每一个请求 都自动携带 token
  interceptors: {
    requestSuccessFn: (config) => {
      let token = localCache.getCache('token')

      if (token && config.headers) {
        config.headers.Authorization = 'Bearer ' + token
      }
      return config
    },
  },
})
console.log('====src/service/index.ts====')
console.log(BASE_URL)

export default hyRequest
